// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var router = require("../hash/pageRouter");
	var dialog = require("dialog");
	var validate = require("validate");
	var databind = require("databind");
	var css_detail_info = require("./clientManage_details.css");
	var html_auditState_Yes = require("../client/clientManage_auditStateYes.html");
	var html_auditState_No = require("../client/clientManage_auditStateNo.html");
	var pageIndex = 1,
		pageSize = 20,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var enterpriseId = "";
	var businessLicenceImage = "";
	var certificateImage = "";
	var legalPersonFrontImage = "";
	var legalPersonBackImage = "";
	var qualificationsImage = "";
	var creditReportImage = "";
	var leftMenu = require("../leftMenu/leftMenu");
	var storage = window.sessionStorage;
    var topMenu = require("../topMenu/topMenu");
	var init = function(page) {
//		enterpriseId = page.params.enterpriseId || base.getUrlParam("enterpriseId");
		enterpriseId = storage.getItem("enterpriseId");
//		enterpriseId = 9;
		$("#header").css("display", "none");
		$("#leftMenu").css("display", "none");
		$(".pages").css("width", "100%");
		leftMenu.init(1);
    	topMenu.init(2);
    	
    	$(".table-section").removeClass("none");
		
		$(".nav_active").removeClass("nav_active1");
		$(".enterpriseInfo").addClass("nav_active1");
		initEvent();
		inquireEnterpriseDetail(enterpriseId);
		router.init();
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			location.href = "../login/login.html";
		}
		$(".button_cancel").on("mouseenter", function() {
			$(".auditState").css("display", "inline-block");
			$(".auditStateNo").css("color", "#000000");
			$(".auditStateYes").css("color", "#000000");
		});

		$(".auditState").on("mouseleave", function() {
			$(".auditState").css("display", "none");
		});
		
		$(".auditStateYes").on("mouseenter", function() {
			$(".auditStateYes").css("color", "blue");
		});

		$(".auditStateYes").on("mouseleave", function() {
			$(".auditStateYes").css("color", "#000000");
		});
		$(".auditStateNo").on("mouseenter", function() {
			$(".auditStateNo").css("color", "blue");
		});

		$(".auditStateNo").on("mouseleave", function() {
			$(".auditStateNo").css("color", "#000000");
		});

		//点击企业基本信息
		$("#clientManageDetailIntact .enterpriseInfo1").on("click", function() {
			location.href = "../client/clientManageDetailIntact.html?enterpriseId=" + enterpriseId;
		});
		

		$(".financeSituation1").on("click", function() {
			router.route("client/clientManage_financeSituation1.html?enterpriseId=" + enterpriseId +
				"&businessLicenceImage=" + businessLicenceImage + "&certificateImage=" + certificateImage +
				"&legalPersonFrontImage=" + legalPersonFrontImage + "&legalPersonBackImage=" + legalPersonBackImage +
				"&qualificationsImage=" + qualificationsImage + "&creditReportImage=" + creditReportImage, true);
		});

		//证明材料
		$(".financeEvidentiary1").on("click", function() {
			router.route("client/clientManage_financeEvidentiary1.html?enterpriseId=" + enterpriseId +
				"&businessLicenceImage=" + businessLicenceImage + "&certificateImage=" + certificateImage +
				"&legalPersonFrontImage=" + legalPersonFrontImage + "&legalPersonBackImage=" + legalPersonBackImage +
				"&qualificationsImage=" + qualificationsImage + "&creditReportImage=" + creditReportImage, true);
		});
		
	};

	var inquireEnterpriseDetail = function(enterpriseId) {
		base.fnAjax({
			action: "inquireEnterpriseDetail.json",
			oData: {
				enterpriseId: enterpriseId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var enterpriseInfo = data.datas[0];
					$("#enterpriseName").text(enterpriseInfo.enterpriseName);
					$("#qualifications").text(enterpriseInfo.qualifications);
					$("#businessLicence").text(enterpriseInfo.businessLicence);
					$("#gradeName").html(enterpriseInfo.gradeName);
					$("#creditLine").text(enterpriseInfo.creditLine);
					$("#address").text(enterpriseInfo.address);
					$("#nature").text(enterpriseInfo.nature);
					$("#contactAddress").text(enterpriseInfo.contactAddress);
					$("#businessTimeLimit").text(enterpriseInfo.businessTimeLimit);
					$("#businessScope").text(enterpriseInfo.businessScope);
					$("#registeredCapital").text(enterpriseInfo.registeredCapital);
					$("#legalPerson").text(enterpriseInfo.legalPerson);
					$("#legalIdcard").text(enterpriseInfo.legalIdcard);
					$("#legalPeriod").text(enterpriseInfo.legalPeriod);
					$("#depositBank").text(enterpriseInfo.depositBank);
					$("#accountHolder").text(enterpriseInfo.accountHolder);
					$("#creditCard").text(enterpriseInfo.creditCard);
					businessLicenceImage = enterpriseInfo.businessLicenceImage;
					certificateImage = enterpriseInfo.certificateImage;
					legalPersonFrontImage = enterpriseInfo.legalPersonFrontImage;
					legalPersonBackImage = enterpriseInfo.legalPersonBackImage;
					qualificationsImage = enterpriseInfo.qualificationsImage;
					creditReportImage = enterpriseInfo.creditReportImage;

					if (enterpriseInfo.auditState == 1) {
						$(".button_cancel").css("display", "inline-block");
					}
				} else {
					base.alert(2, data.message);
				}
			}
		});
	}

	return {
		init: init
	};
});